﻿using System;
using System.Collections.Generic;

namespace EmbeddedSharp.Core {
    public class VariableMapper {
        private Dictionary<string, string> mapping = new Dictionary<string, string>();

        public string Add(string key) {
            if (mapping.ContainsKey(key)) {
                return mapping[key];
            }

            Random ran = new Random();
            string value = "A" + ran.Next().ToString();
            while (mapping.ContainsKey(value)) {
                value = "A" + ran.Next().ToString();
            }

            mapping.Add(key, value);

            return value;
        }

        public bool ContainsKey(string key) {
            return mapping.ContainsKey(key);
        }

        public string Value(string key) {
            if (mapping.ContainsKey(key)) {
                return mapping[key];
            }

            return null;
        }
    }
}
